<?php

if (! defined ( 'IN_DISCUZ' )) {
	exit ( 'Access Denied' );
}

require_once 'com_fun.php';

$query=$_G['gp_query'];

if($query=='query')
{
	$keyword=$_G['gp_keyword'];
	
	if(!$keyword)
	{
		echo 'keyword error';
		return;
	}
	
	$key='808a3ac9ef1390a5b2579eddf3432db7';
	
	$keyword=urlencode($keyword);
	
	$url="http://v.juhe.cn/dream/query?q=$keyword&cid=&full=&key=$key";	
//	$url="http://127.0.0.1/fytools/source/plugin/fytools/interface/dream_list.txt";
	
	$content = file_get_contents($url);
	
	if(!$content)
	{
		echo "content error";
		return;
	}
	else
	{
		//echo $content;
	}
	//$content=iconv('gbk','utf-8', $content);
	$result = json_decode($content);
	
	if($result)
	{
	
		if($result->error_code==0)
		{

			$dreamArray=$result->result;
	//		var_dump($dreamArray);
			
		}else
		{
			echo $result['error_code'].":".$result['reason'];
			return ;
		}
	}
	else
	{
		echo "json_decode error";
	
	}
	
	include template('fytools:dream-detial');
}
else
{

	include template('fytools:Dream');
}
	



